#!/usr/bin/node

/*eslint no-console: 0*/

"use strict";
const env = process.env.mode || "dev";
const chalk = require("chalk");
const path = require("path");
const Irc = require("tmi.js");

const credentials = require(path.join(__dirname, "config", env, "credentials"))[env];
const logger = require(path.join(__dirname, "app", "middlewares", "logger"))();
const client = new Irc.client(credentials());

const displayChannels = function(channels) {
  if (1 === channels.length) {
    return;
  }
  channels.shift();
  channels.forEach(function(channel) {
    console.info("\t\t\t" + channel);
  });
};

console.info("--------------------------------------------\n");
console.info("\t,___,");
console.info("\t{O,o}\t\t" + chalk.bold("Owls Bot"));
console.info("\t|)``)\t\t");
console.info("\t------\n\r");
console.info("--------------------------------------------\n");
console.info("Environment : " + chalk.yellow(env));
console.info("Credentials :");
console.info("\t" + chalk.yellow("bot name") +
             (":\t") + credentials().identity.username);
console.info("\t" + chalk.yellow("channels") +
             (":\t") + credentials().channels[0]);
displayChannels(credentials().channels);
console.info("\n--------------------------------------------\n");

logger.info("started");

client.connect();
